package org.misalen.web.admin.controllers;

import java.util.UUID;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.misalen.web.admin.shiro.ShiroUser;
import org.misalen.web.admin.util.ServerResult;
import org.misalen.web.database.BaseRepository;
import org.misalen.web.service.file.OssFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * BaseController
 * 
 * @author guochao
 *
 */
@Component
public class BaseController extends BaseRepository {

	protected static Logger logger;

	@Autowired
	protected OssFile ossFile;

	public BaseController() {
		logger = Logger.getLogger(getClass());
	}

	protected void log(String log) {
		ShiroUser user = getShiroUser();
		logger.error(user.getNickname() + "-(" + user.getUsername() + ")\t" + log);
	}

	public ShiroUser getShiroUser() {
		ShiroUser user = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
		return user;
	}

	public ServerResult renderError(String msg) {
		return ServerResult.error(msg);
	}

	public ServerResult renderSuccess() {
		return ServerResult.ok();
	}

	public ServerResult renderSuccess(Object obj) {
		return ServerResult.ok(obj);
	}

	public String getUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}

}
